package com.dhh.util.manager;

import java.util.Calendar;

import com.dhh.dao.DataBaseHelper;
import com.dhh.dao.PlanDAO;
import com.dhh.util.CUtil;
import com.dhh.util.calorie.CalUtil;
import com.dhh.util.calorie.FoodLevelPattern;
import com.dhh.vo.FoodPlan;
import com.dhh.vo.Goal;
import com.dhh.vo.PlanItem;

public class PlanManager {
	private PlanDAO dao;
	
	public PlanManager(DataBaseHelper db){
		dao = new PlanDAO(db);
	}
	
	public FoodPlan getPlan(String gid){
		return dao.getFoodPlanByGoalId(gid);
	}
	
	public FoodPlan getCurrentPlan(){
		return dao.getCurrentPlan();
	}
	
	public FoodPlan getCurrentPlanSimple(){
		return dao.getCurrentPlanSimple();
	}
	
	public boolean removePlanItem(String pItemId){
		return dao.removePlanItem(pItemId);
	}
	
	public boolean removePlanItemByParent(String parentId){
		return dao.removePlanItemByParent(parentId);
	}
	
	public boolean addPlanItem(PlanItem item){
		return dao.addPlanItem(item);
	}
	
	public void addPlan(Goal goal){
		FoodPlan plan = new FoodPlan();
		int rcal = CalUtil.getCal(goal);
		int cal = CalUtil.convertCal(rcal);		
		plan.setGrain(FoodLevelPattern.getValue(cal, FoodLevelPattern.FOOD_GRAIN));
		plan.setFruit(FoodLevelPattern.getValue(cal, FoodLevelPattern.FOOD_FRUIT));
		plan.setDairy(FoodLevelPattern.getValue(cal, FoodLevelPattern.FOOD_DAIRY));
		plan.setVegetable(FoodLevelPattern.getValue(cal, FoodLevelPattern.FOOD_VEGETABLE));
		plan.setProteinFood(FoodLevelPattern.getValue(cal, FoodLevelPattern.FOOD_PROTEIN));
		plan.setEnergy(String.valueOf(rcal));
		plan.setGoal(goal.getId());
		plan.setDate(CUtil.getDate(Calendar.getInstance().getTime()));
		dao.addPlan(plan);
	}
}
